//聚衣汇-首页
function jyihui_i() {
    let mockData = Mock.mock({

    });
    new Vue({
        el: "#jyihui_i",
        data() {
            return {
                list: [],
                pageNo: 1,
                total: 0,
                bannerlist: [],
                topimgs: [{},{},{},{}],
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 3,
                    outId: null
                },
                formLabelWidth: '120px',
                index:0,

            }
        },
        methods: {
            getData() {
                var that = this;
                //获取广告(上面的轮播)
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.bannerlist = response.data.data;
                            //console.log(that.bannerlist);
                        }
                    }
                });
                //获取广告(首页轮播下面的广告位)
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiSecondPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.topimgs = response.data.data;

                        }
                    }
                });
                //行业订购会 /api/clothes/orderingMeeting/lineList 暂时未换
                axios.get(urlParam.domain() + '/api/clothes/orderingMeeting/lineList', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 9,
                        token: urlParam.token()
                    }
                }).then(function(response) {
                    //console.log(response.data.data.list);
                    that.list = response.data.data.list;
                    that.total = getPageCount(response.data.data.total, 9);
                });
            },
            getPage(page) {
                this.pageNo = page;
                this.getData();
            },
            //报名
            baoming(item,index) {
                window.location.href = urlParam.location() + "/jyihui/shizz_detail.html?type=3&id="+item.id
            },
            //取消报名
            unBaoming(item,index){
                axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                    params: {
                        outId: item.id,
                        outType: 3,
                        token:urlParam.token()
                    }
                }).then(
                    function(r) {
                        that.$message({
                            message: '取消成功',
                            type: 'success'
                        });
                        that.list[that.index].beApplied=false;
                    }

                )
            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                that.form.token=urlParam.token();
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form
                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;
                that.list[that.index].beApplied=true;
            },

        },
        created() {
            this.getData();
        },
        components: {
            'common-swiper': common_swiper,
            'common-biaoti': common_biaoti
        }
    });
}

//聚衣汇-时装周
function jyihui_szz() {
    let mockData = Mock.mock({

    });
    new Vue({
        el: "#jyihui_szz",
        data() {
            return {
                'ordertype_cur': 0,
                crumblist: [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚衣汇'
                }, {
                    'href': '',
                    'text': '聚衣时装周'
                }],
                list: [],
                pageNo: 1,
                total: 0,
                mark: 1,
                title: "",
                messages: "",
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 1,
                    outId: null,
                    token:""
                },
                formLabelWidth: '120px',
                index:0
            }
        },
        methods: {
            getData() {
                var that = this;
                axios.get(urlParam.domain() + '/api/clothes/fashionWeek/allWeekList', {
                        params: {
                            pageNo: that.pageNo,
                            pageSize: 9,
                            title: that.title,
                            token: urlParam.token()
                        }
                    })
                    .then(function(response) {
                        console.log(response.data.data);
                        if (that.mark == 1) {
                            that.list = response.data.data.map.thisWeekList;
                            that.total = getPageCount(response.data.data.thisTotal, 9);
                        } else {
                            that.list = response.data.data.map.preWeekList;
                            //console.log(that.list.length);
                            that.total = getPageCount(response.data.data.preTotal, 9);
                        }
                    });
            },
            getPage(page) {
                this.pageNo = page;
                this.getData();
                this.pageNo = 1;
            },
            getList(msg, event) {
                this.mark = msg;
                this.ordertype_cur = msg - 1;
                this.getData();
            },
            /*查询时装周*/
            getSearch(event) {
                this.pageNo = 1;
                this.title = this.messages;
                this.getData();
            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                that.form.token=urlParam.token();
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form,

                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                    that.list[that.index].beApplied=true;
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;
                /*that.getData();*/
            },
            //取消报名，或者可报名出现对话框
            showbaoming(data,index) {
                let that = this;

                that.index=index;
                if (data.beApplied) {
                    axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                        params: {
                            outId: data.id,
                            outType: 1,
                            token:urlParam.token()
                        }
                    }).then(
                        function(r) {
                            that.$message({
                                message: '取消成功',
                                type: 'success'
                            });
                        }
                    )
                    that.list[that.index].beApplied=false;
                }else{
                    if (urlParam.token() == ''||urlParam.token()==null) {
                        this.$message({
                            message: '登录之后才可以报名哦',
                            type: 'warning'
                        });
                        return;
                    }else{
                        that.form.outId = data.id;
                        that.dialogFormVisible = true;
                    }
                }
            }
        },
        created() {
            this.getData();
        },
        components: {
            'common-swiper': common_swiper,
            'common-biaoti': common_biaoti,
            'base-list': jyihui_base_szzlist
        }
    });
}

//聚衣汇-采购会
function jyihui_mqcg() {
    let mockData = Mock.mock({

    });
    new Vue({
        el: "#jyihui_mqcg",
        data() {
            return {
                crumblist: [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚衣汇'
                }, {
                    'href': '',
                    'text': '名企采购会'
                }],
                list: [],
                pageNo: 1,
                total: 0,
                bannerlist: [],
                adList: [],
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 3,
                    outId: null,
                    token:""
                },
                formLabelWidth: '120px'
            }
        },
        methods: {
            getData() {
                var that = this;

                //获取广告Banner
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiCaiGouPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.bannerlist = response.data.data;
                        }
                    }

                });

                axios.get(urlParam.domain() + '/api/clothes/purchasingMeeting/list', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 9,
                        token:urlParam.token()
                    }
                }).then(function(response) {
                    //console.log(response.data);
                    that.list = response.data.data.list;
                    that.total = getPageCount(response.data.data.total, 9);
                });
            },
            getPage(page) {
                this.pageNo = page;
                this.getData();

            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                that.form.token=urlParam.token();
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form,

                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                    that.list[that.index].beApplied=true;
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;
            },
            showbaoming(data,index) {
                //名企采购
                let that = this;
                that.index=index;
                if (data.beApplied) {
                    axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                        params: {
                            outId: data.id,
                            outType: 3,
                            token:urlParam.token()
                        }
                    }).then(
                        function(r) {
                            that.$message({
                                message: '取消成功',
                                type: 'success'
                            });
                            that.list[that.index].beApplied=false;
                        }
                    )
                }else{
                    if (urlParam.token() == ''||urlParam.token()==null) {
                        this.$message({
                            message: '登录之后才可以报名哦',
                            type: 'warning'
                        });
                        return;
                    }else{
                        that.form.outId = data.id;
                        that.dialogFormVisible = true;

                    }
                }

            },
        },
        created() {
            this.getData();
        },
        components: {
            'common-swiper': common_swiper,
            'common-biaoti': common_biaoti,
            'base-list': jyihui_base_list,

        }
    });
}

//聚衣汇-品牌招商会
function jyihui_ppzsh() {
    let mockData = Mock.mock({

    });
    new Vue({
        el: "#jyihui_ppzsh",
        data() {
            return {
                crumblist: [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚衣汇'
                }, {
                    'href': '',
                    'text': '品牌招商会'
                }],
                list: [],
                pageNo: 1,
                total: 0,
                bannerlist: [],
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 4,
                    outId: null
                },
                formLabelWidth: '120px',
               /* index:0*/
            }
        },
        methods: {
            getData() {
                var that = this;

                //获取广告
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiCaiGouPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.bannerlist = response.data.data;
                        }
                    }
                });
                axios.get(urlParam.domain() + '/api/clothes/investmentMeeting/list', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 9,
                        token:urlParam.token()
                    }
                }).then(function(response) {
                    console.log(response.data.data.list);
                    that.list = response.data.data.list;
                    that.total = getPageCount(response.data.data.total, 9);
                });
            },
            getPage(page) {
                this.pageNo = page;
                this.getData();

            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                that.form.token=urlParam.token();
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form,

                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                    that.list[that.index].beApplied=true;
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;
            },
            showbaoming(data,index) {
                let that = this;
                that.index=index;
                if (data.beApplied) {
                    axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                        params: {
                            outId: data.id,
                            outType: 4,
                            token:urlParam.token()
                        }
                    }).then(
                        function(r) {
                            that.$message({
                                message: '取消成功',
                                type: 'success'
                            });
                            that.list[that.index].beApplied=false;
                        }
                    )
                }else{
                    if (urlParam.token() == ''||urlParam.token()==null) {
                        this.$message({
                            message: '登录之后才可以报名哦',
                            type: 'warning'
                        });
                        return;
                    }else{
                        that.form.outId = data.id;
                        that.dialogFormVisible = true;

                    }

                }

            },
        },
        created() {
            this.getData();
        },
        components: {
            'common-swiper': common_swiper,
            'common-biaoti': common_biaoti,
            'base-list': jyihui_base_list,

        }
    });
}

//聚衣汇-行业订购会
function jyihui_hydg() {
    let mockData = Mock.mock({

    });
    new Vue({
        el: "#jyihui_hydg",
        data() {
            return {
                crumblist: [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚衣汇'
                }, {
                    'href': '',
                    'text': '行业订购会'
                }],
                list: [],
                pageNo: 1,
                total: 0,
                bannerlist: [],
                adList: [],
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 2,
                    outId: null,
                    token:""
                },
                formLabelWidth: '120px',
                ordertype_cur: 0,
                mark:0,
                index:0//传递索引
            }
        },
        methods: {
            getData() {
                var that = this;

                //获取广告
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiDinggouPosition()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.bannerlist = response.data.data;
                        }
                    }

                });

                //获取广告
                axios.get(urlParam.domain() + '/api/advert/list', {
                    params: {
                        position: urlParam.jyihuiDinggouAd()
                    }
                }).then(function(response) {
                    if (response.data.code == 1) {
                        if (response.data.data != undefined) {
                            that.adList = response.data.data;
                        }
                    }

                });

                axios.get(urlParam.domain() + '/api/clothes/orderingMeeting/allLineList', {
                    params: {
                        pageNo: that.pageNo,
                        pageSize: 16,
                        token:urlParam.token()
                    }
                }).then(function(response) {
                    console.log(response.data.data);
                    if (that.mark == 0) {
                        that.list = response.data.data.map.onlinelist;
                        that.total = getPageCount(response.data.data.onLineTotal, 16);
                    } else {
                        that.list = response.data.data.map.linelist;
                       // console.log(that.list.length);
                        that.total = getPageCount(response.data.data.lineTotal, 16);
                    }
                });
            },
            getPage(page) {
                this.pageNo = page;
                this.getData();

            },
            //切换线上订购会/线下订购会
            getList(val) {
                this.ordertype_cur = val;
                this.mark=val;
            },
            //收藏
            addShouc(index,data) {
                if (urlParam.token() == ''||urlParam.token()==null) {
                    this.$message({
                        message: '登录之后才可以收藏哦',
                        type: 'warning'
                    });
                    return;
                }
                let that=this;
                axios.get(urlParam.domain()+"/api/clothes/clothesFollow/add",{
                    params:{
                        token:urlParam.token(),
                        outId:data.id,
                        outType:2
                    }
                }).then(function(){
                    that.$message({
                        message: '收藏成功',
                        type: 'success'
                    });
                    data.followId = data.id;
                })
            },
            //取消收藏
            quitShouc(index,data) {
                if (urlParam.token() == ''||urlParam.token()==null) {
                    this.$message({
                        message: '登录之后才可以取消收藏哦',
                        type: 'warning'
                    });
                    return;
                }
                let that=this;
                axios.get(urlParam.domain()+"/api/clothes/clothesFollow/delete",{
                    params:{
                        token:urlParam.token(),
                        outId:data.id,
                        outType:2
                    }
                }).then(function(){
                    that.$message({
                        message: '取消收藏成功',
                        type: 'success'
                    });
                    data.followId = null;
                })
            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                that.form.token=urlParam.token();

                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form

                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;
                this.list[this.index].beApplied=true;
            },
            //取消报名，或者可报名出现对话框
            baoming(item,index) {
                let that = this;
                if (item.beApplied) {
                    axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                        params: {
                            outId: item.id,
                            outType: 2,
                            token:urlParam.token()
                        }
                    }).then(
                        function(r) {
                            that.$message({
                                message: '取消成功',
                                type: 'success'
                            });
                            that.getData();
                        }
                    )
                }else{
                    if (urlParam.token() == ''||urlParam.token()==null) {
                        this.$message({
                            message: '登录之后才可以报名哦',
                            type: 'warning'
                        });
                        return;
                    }
                    that.form.outId = item.id;
                    that.dialogFormVisible = true;
                    that.index=index;
                }
            },
            //致电
            showphone(item){
                this.$alert(item.telephone, '热线电话', {
                    confirmButtonText: '确定', callback: action => {
                    }
                });
            }
        },
        created() {
            this.getData();
        },
        components: {
            'common-swiper': common_swiper,
        },
        watch: {
            ordertype_cur: {
                handler() {
                    this.getData();
                }
            }
        }
    });
}

//聚衣汇-时装周详情
function jyihui_szz_detail() {
    new Vue({
        el: "#jyihui_szz_detail",
        data() {
            return {
                'crumblist': [{
                    'href': '',
                    'text': '首页'
                }, {
                    'href': '',
                    'text': '聚衣汇'
                }, {
                    'href': '',
                    'text': '聚衣丝绸时装周'
                }],
                article: null,
                dialogFormVisible: false,
                form: {
                    companyName: "",
                    personName: "",
                    age: null,
                    sex: null,
                    phone: "",
                    status: null,
                    outType: 3,
                    outId: null
                },
                formLabelWidth: '120px'
            }
        },
        methods: {
            getData() {
                var that = this;

                var params = globalAPI.getRequest();

                var url = "";
                if(params.type == 1){ //时装周详情
                    url = '/api/clothes/fashionWeek/detail';
                }else if(params.type == 2){ //名企采购
                    url = '/api/clothes/purchasingMeeting/detail';
                }else if(params.type == 3){ //品牌招商
                    url = '/api/clothes/investmentMeeting/detail';
                }else if(params.type == 4){ //行业订购
                    url = '/api/clothes/orderingMeeting/detail';
                }

                axios.get(urlParam.domain() + url, {
                        params: {
                            id: params.id
                        }
                    })
                    .then(function(response) {
                        console.log(response.data);
                        that.article = response.data.data
                    });
            },
            //取消报名，或者可报名出现对话框
            baoming(index) {
                if (urlParam.loginName() == '') {
                    this.$message({
                        message: '登录之后才可以报名哦',
                        type: 'warning'
                    });
                    return;
                }
                var flag = false;
                if (index.beApplied) {
                    axios.get(urlParam.domain() + '/api/clothes/checked/quit', {
                        params: {
                            outId: index.id,
                            outType: 3
                        }
                    }).then(
                        function(r) {
                            that.$message({
                                message: '取消成功',
                                type: 'success'
                            });
                            flag = true;
                        }

                    ).catch()
                }

                if (flag) {
                    return;
                }
                let that = this;
                that.form.outId = index.id;
                that.dialogFormVisible = true;
            },
            /*提交报名的方法*/
            baomingok() {
                let that = this;
                that.form.status = 1;
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/clothes/checked/add',
                    params: this.form
                }).then(function(r) {
                    that.$message({
                        message: '报名成功',
                        type: 'success'
                    });
                }).catch(function(e) {
                    that.$message({
                        message: "出现错误",
                        type: "error"
                    })
                })
                this.dialogFormVisible = false;

            }
        },
        created() {
            this.getData();
        },
        components: {
            'base-article': base_article
        }
    });
}

//聚衣汇-名企采购/品牌招商
let jyihui_base_list = {
    props: ['list'],
    template: `<div class="jyh-dglist mt-20">
    <div v-for="(item,index) of list" v-if="index<9" class="jyh-dgitem">
        <img :src="item.picUrl">
        <div class="jyh-dgbottom">
            <p class="title">{{item.title}}</p>
            <p class="location">{{item.address}}</p>
            <p class="date">{{item.startTime}}--{{item.endTime}}</p>
        </div>
        <div class="intro">
            <p class="line1">{{item.title}}</p>
            <p class="txt">{{item.content}}</p>
             <button class="baoming" @click="baoming(item,index)" v-if="!item.beApplied">马上报名</button>
            <button class="baoming" @click="baoming(item,index)"  v-if="item.beApplied">取消报名</button>
        </div>
    </div>
</div>`,
    methods: {
        baoming: function(data,index) {
            window.location.href = urlParam.location() + "/jyihui/shizz_detail.html?type=2&id="+data.id
            /*if (urlParam.token() == ''||urlParam.token() ==null) {
                this.$message({
                    message: '登录之后才可以报名哦',
                    type: 'warning'
                });
                return;
            }            
            this.$emit('callback',data,index)*/
        }

    }
}

//聚衣汇-时装周
let jyihui_base_szzlist = {
    props: ['list'],
    template: `<div class="jyh-dglist mt-20">
    <div v-for="(item,index) of list" v-if="index<9" class="jyh-dgitem">
        <img :src="item.picUrl">
        <div class="jyh-dgbottom">
            <p class="title">{{item.title}}</p>
            <p class="location">{{item.address}}</p>
            <p class="date">{{item.startTime}}--{{item.endTime}}</p>
        </div>
        <div class="intro">
            <p class="line1">活动介绍</p>
            <p class="txt">{{item.content}}</p>
             <button class="baoming" @click="baoming(item,index)" v-if="!item.beApplied">马上报名</button>
            <button class="baoming" @click="baoming(item,index)"  v-if="item.beApplied">取消报名</button>
        </div>
    </div>
</div>`,
    methods: {
        baoming: function(data,index) {
            console.log(data);
            window.location.href = urlParam.location() + "/jyihui/shizz_detail.html?type=1&id="+data.id

            /*if (urlParam.token() == ''||urlParam.token() ==null) {
                this.$message({
                    message: '登录之后才可以报名哦',
                    type: 'warning'
                });
                return;
            }
            this.$emit('callback',data,index)*/
        }
    }
}
